package com.cat.twoPointerTechnique;

import java.util.Arrays;
/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/reduction-operations-to-make-the-array-elements-equal/description/
 * @create 2025/8/8 14:36
 * @since JDK17
 */

public class Solution22 {
    public int reductionOperations(int[] nums) {
        int n = nums.length - 1, ans = 0, t;
        Arrays.sort(nums);
        for (int i = 0, j = n; i < j; i++, j--) {
            t = nums[i];
            nums[i] = nums[j];
            nums[j] = t;
        }
        for (int i = 0; i < n; i++) {
            while (i < n && nums[i] == nums[i + 1]) {
                i++;
            }
            if (i != n) ans += i + 1;
        }
        return ans;
    }
}